// pages/xzMap/new_property.js
const app = getApp()

import {
  property_register
} from '../../api/request'

Page({
  data: {
    Input_Data: {
      liaison_man: '', //联系人
      liaison_tel: '', //联系电话
      property_num: '0', //小区住户规模
      wechat: '', //微信号
      cur_job_index: 0, //当前阶段
      property_hot: '', //关切热点
    },

    cur_job: ['成立业委会', '业委会换届', '选聘物管', '其它'],
    province: '', //省市
    city: '', //城市
    district: '', //区县

    property_address: [], //腾讯小区地址信息
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;

    this.setData({
      property_address: wx.getStorageSync('PROPERTY_ADDRESS'),
    })

    var property_hot = '成立业委会业主不积极、收集20%业主签名难、业委会投票“双过半”难、小区派系多/分歧大、业主/物管矛盾大、未续聘物管、希望选聘物管、“双过半”投票表决、物管服务调查、物管服务评价、业主意见征集、大修基金使用申请表决' //关切热点
    if (that.data.property_address.province == undefined) {
      var Input_Data = this.data.Input_Data
      Input_Data['liaison_man'] = app.globalData.cur_my_name
      Input_Data['liaison_tel'] = app.globalData.phoneNumber
      Input_Data['wechat'] = app.globalData.phoneNumber
      Input_Data['property_num'] = '0' //小区住户规模 
      Input_Data['property_hot'] = property_hot

      this.setData({
        Input_Data,
        province: that.data.property_address.ad_info.province,
        city: that.data.property_address.ad_info.city,
        district: that.data.property_address.ad_info.district,
      })

    } else {
      var Input_Data = this.data.Input_Data
      Input_Data['liaison_man'] = app.globalData.cur_my_name
      Input_Data['liaison_tel'] = app.globalData.phoneNumber
      Input_Data['wechat'] = app.globalData.phoneNumber
      Input_Data['property_num'] = '0' //小区住户规模 
      Input_Data['property_hot'] = property_hot

      this.setData({
        Input_Data,
        province: that.data.property_address.province,
        city: that.data.property_address.city,
        district: that.data.property_address.district,
      })
    }

  },

  bindPickerChange(e) {
    var Input_Data = this.data.Input_Data
    Input_Data[e.currentTarget.id] = e.detail.value
    this.setData({
      Input_Data
    })
  },

  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  //小区申请开通
  submit() {
    let that = this;
    /*
        m_property_name in varchar, --小区名字
        m_address in varchar, --地址
        m_latitude in varchar, --经度
        m_longitude in varchar, --纬度
        m_province in varchar, --省市
        m_city in varchar, --城市
        m_district in varchar, --区县
        m_liaison_man in varchar, --联系人
        m_liaison_tel in varchar, --联系电话
        m_property_num in varchar, --小区规模
        m_property_hot in varchar, --关切热点
    */

    var data = {
      para: [that.data.property_address.title,
        that.data.property_address.address,
        that.data.property_address.location.lat,
        that.data.property_address.location.lng,
        that.data.province,
        that.data.city,
        that.data.district,
        that.data.Input_Data.liaison_man,
        that.data.Input_Data.liaison_tel,
        that.data.Input_Data.property_num,
        that.data.Input_Data.property_hot,
        that.data.Input_Data.wechat,
        that.data.Input_Data.cur_job_index,

      ]
    }
    property_register(data).then(res => {
      app.globalData.cur_property_code = res.data[0].PROPERTY_CODE
      app.globalData.cur_property_name = res.data[0].PROPERTY_NAME
      app.globalData.cur_room_code = '请实名认证'
      wx.setStorageSync('property_code', res.data[0].PROPERTY_CODE)

      wx.switchTab({
        url: '/pages/home/index',
        success(res) {
          let page = getCurrentPages().pop();
          if (page == undefined || page == null) {
            return
          }
          page.home_flush(); //刷新主页面
        }

      })

      wx.showModal({
        title: '小区申请开通',
        confirmText: "确定",
        showCancel: false,
        content: '小区申请开通信息已提交，我们将及时与你联系，请保持电话畅通',
      })


    })

  },
  field_change(e) {
    var Input_Data = this.data.Input_Data
    Input_Data[e.currentTarget.id] = e.detail
    this.setData({
      Input_Data
    })
  },

  getInput(e) {
    var Input_Data = this.data.Input_Data
    Input_Data[e.currentTarget.dataset.id] = e.detail.value
    this.setData({
      Input_Data
    })
  },


})